package com.dragon.modules.yuegou.client.wechat_mini.service.impl;

import com.dragon.modules.yuegou.client.wechat_mini.client.MiniClient;
import com.dragon.modules.yuegou.client.wechat_mini.client.impl.MiniClientImpl;
import com.dragon.modules.yuegou.client.wechat_mini.common.MiniConfig;
import com.dragon.modules.yuegou.client.wechat_mini.security.AccessTokenRepository;
import com.dragon.modules.yuegou.client.wechat_mini.security.AccessTokenService;
import com.dragon.modules.yuegou.client.wechat_mini.security.DefaultAccessTokenRepository;
import com.dragon.modules.yuegou.client.wechat_mini.security.impl.AccessTokenServiceImpl;
import com.dragon.modules.yuegou.client.wechat_mini.service.AuthService;
import com.dragon.modules.yuegou.client.wechat_mini.service.LiveService;
import com.dragon.modules.yuegou.client.wechat_mini.service.MiniService;
import com.dragon.modules.yuegou.client.wechat_mini.service.SecurityService;
import com.dragon.modules.yuegou.client.wechat_mini.service.SubscribeMessageService;
import com.dragon.modules.yuegou.client.wechat_mini.service.WxaCodeService;

/**
 * 小程序服务（单小程序版）实现
 * 
 * @author liuwu
 *
 */
public class MiniServiceImpl implements MiniService {

	/**
	 * 接口凭证服务
	 */
	private final AccessTokenService tokenService;

	/**
	 * 认证服务
	 */
	private final AuthService auth;

	/**
	 * 订阅消息服务
	 */
	private final SubscribeMessageService subscribeMessage;

	/**
	 * 微信小程序码服务
	 */
	private final WxaCodeService wxaCode;
	
	/**
	 * 内容安全服务
	 */
	private final SecurityService security;
	
	/**
	 * 直播服务
	 */
	private final LiveService live;

	/**
	 * 构建一个小程序服务
	 * 
	 * @param config 小程序配置
	 */
	public MiniServiceImpl(MiniConfig config) {
		this(config, new MiniClientImpl(), new DefaultAccessTokenRepository());
	}

	/**
	 * 构建一个小程序服务
	 * 
	 * @param config                小程序配置
	 * @param client                小程序客户端
	 * @param accessTokenRepository 接口凭证仓库，如需集群部署，请使用或自行实现共享数据仓库（例如CacheAccessTokenRepositoryImpl）
	 */
	public MiniServiceImpl(MiniConfig config, MiniClient client, AccessTokenRepository accessTokenRepository) {
		super();
		this.tokenService = new AccessTokenServiceImpl(client.auth(), accessTokenRepository, config);
		this.auth = new AuthServiceImpl(client.auth(), config, this.tokenService);
		this.subscribeMessage = new SubscribeMessageServiceImpl(client.subscribeMessage(), tokenService);
		this.wxaCode = new WxaCodeServiceImpl(client.wxaCode(), tokenService);
		this.security = new SecurityServiceImpl(client.security(), tokenService);
		this.live = new LiveServiceImpl(client.live(), tokenService);
	}

	@Override
	public AccessTokenService tokenService() {
		return tokenService;
	}

	@Override
	public AuthService auth() {
		return auth;
	}

	@Override
	public SubscribeMessageService subscribeMessage() {
		return subscribeMessage;
	}

	@Override
	public WxaCodeService wxaCode() {
		return wxaCode;
	}

	@Override
	public SecurityService security() {
		return security;
	}

	@Override
	public LiveService live() {
		return live;
	}

}
